package gui;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

@SuppressWarnings("serial")
public class FileChooser extends JFrame
{
    private final String OpenFileChooser = "Open";
    // private final String SaveFileChoooser ="Save";
    private JFileChooser jFileChooser;
    // private String type;
    public String file = "sssssss";

    public FileChooser(String type)
    {
        // setNativeLookAndFeel();
        initComponents();
        // this.type = type;
        FileFilter fe = new FileNameExtensionFilter("svg file *.svg", "svg");
        jFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        jFileChooser.addChoosableFileFilter(fe);
        setResizable(false);
        setLocationRelativeTo(null);
        setVisible(true);
        setSize(500, 400);

        if (type.equals(OpenFileChooser)) setTitle("Open SVG");
        else setTitle("Save SVG");
    }

    private void initComponents()
    {
        jFileChooser = new javax.swing.JFileChooser();
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jFileChooser.setAcceptAllFileFilterUsed(false);
        getContentPane().add(jFileChooser);
        setLocationRelativeTo(this);
        jFileChooser.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                ActionListener(evt);

            }
        });

    }

    private void ActionListener(java.awt.event.ActionEvent evt)
    {
        if (evt.getActionCommand().equals("ApproveSelection"))
        {
            // System.out.println(jFileChooser.getSelectedFile().toString());
            file = new String(jFileChooser.getSelectedFile().toString());
            System.out.println(file);
        }
        dispose();
    }

    public String getSelected()
    {
        return file;

    }
}
